﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.BLL.SiteAdmin;
using Jzy.Model.SiteAdmin;

using Jzy.Common;
using Jzy.Core.Admin.Company;

namespace Jzy.Web.SiteAdmin.Company
{
    public partial class Edit : PageEdit
    {
        private CompanyBO Company
        {
            get
            {
                return CompanyBO.Instance<CompanyBO>();
            }
        }

        public MenuBO Memu
        {
            get
            {
                return MenuBO.Instance<MenuBO>();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(this.PKID))
                {
                    DispInfo();
                }
            }
        }

        private void DispInfo()
        {
            CompanyInfo info = this.Company.GetInfo(this.PKID);
            this.SetControl(pnlMain, info);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            CompanyInfo info = this.Company.GetInfo(this.PKID);

            if (!string.IsNullOrEmpty(LoginName.Text))
            {
                if (this.Company.ExistField("LoginName", LoginName.Text.Trim(), this.PKID))
                {
                    Alert("登录名已存在");
                    return;
                }
            }

            this.SetEntity(pnlMain, info);
            if (info.Email == null)
            {
                info.Email = "";
            }

            if (!string.IsNullOrEmpty(info.SiteDomain))
            {
                info.SiteDomain = info.SiteDomain.Replace("http://", "").Replace("www.", "").Replace("，", ",");
            }

            if (this.Company.ExistField("SiteDomain", info.SiteDomain, this.PKID))
            {
                Alert("已存在相当的域名，请重新选择");
                return;
            }

            this.Company.Save(info);



            this.RefreshView();

        }
    }
}